<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------

namespace app\controller\admin\v1\giftcard;

use app\controller\admin\AuthController;
use app\model\v1\gift\GiftCard;
use app\model\v1\gift\GiftCardBatch;
use app\model\v1\gift\GiftCardBless;
use app\model\v1\gift\GiftCardCate;
use app\model\v1\gift\GiftCardEffect;
use app\model\v1\gift\GiftCardNumber;
use app\model\v1\gift\GiftCardReport;
use app\model\v1\recovery\ConfigBanner;
use app\model\v1\recovery\ConfigCost;
use app\model\v1\recovery\SystemOperationLog;
use app\model\v1\gift\GiftCardSys;
use app\model\v1\gift\GiftCardUser;
use app\Request;
use app\services\article\ArticleCategoryServices;
use crmeb\services\CacheService;
use think\facade\App;

/**
 * 求职招聘管理
 * Class ArticleCategory
 * @package app\controller\admin\v1\cms
 */
class GiftCollection extends AuthController
{
    protected $model;

    public function __construct(App $app, GiftCardCate $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }


    /**
     * 礼品卡后台 - 礼品卡管理列表
     * @param Request $request
     * @return mixed
     */
    public function getGiftCardList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCard::getGiftCardDataList($param);

        return $this->success($data);
    }


    /**
     * 礼品卡管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addGiftCard(Request $request)
    {
        $param = $request->post();
        if(empty($param['tag_id'])) return $this->fail('tag_id不能为空');
        if(empty($param['title'])) return $this->fail('title不能为空');
        if(empty($param['price'])) return $this->fail('price不能为空');
        if(empty($param['price_text'])) return $this->fail('price_text不能为空');
        if(empty($param['img'])) return $this->fail('img不能为空');
        if(empty($param['detail_chart'])) return $this->fail('detail_chart不能为空');
        if(empty($param['theme'])) return $this->fail('theme不能为空');
        if(empty($param['content'])) return $this->fail('content不能为空');
        if(empty($param['unit'])) return $this->fail('unit不能为空');
        if(empty($param['stock_num'])) return $this->fail('stock_num不能为空');
        if(empty($param['original_price'])) return $this->fail('original_price不能为空');
        ////if(empty($param['subscript_price'])) return $this->fail('subscript_price不能为空');
        if(empty($param['bless'])) return $this->fail('祝福语不能为空');
        if(empty($param['make_start_price'])) return $this->fail('make_start_price不能为空');
        if(empty($param['normal'])) return $this->fail('normal不能为空');
        if(!empty($param["bless"])){
            //if(empty($param['ground'])) return $this->fail('ground不能为空');
        }
        if(!empty($param["price2"])){
            if(empty($param['price2_text'])) return $this->fail('price2_text不能为空');
            if(count(explode(",", $param['price2'])) != count(explode(",", $param['price2_text']))) return $this->fail('price2_text数量不正确！');
        }

        $res = GiftCard::addGiftCard($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }




    /**
     * 礼品卡管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateGiftCard(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['title'])) return $this->fail('title不能为空');

        $res = GiftCard::updateGiftCard($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：标题：{$param['title']}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','礼品卡管理列表','updateGiftCard','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }



    /**
     * 礼品卡管理列表 - 删除
     * @return void
     */
    public function deleteGiftCard(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCard::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','礼品卡管理列表','deleteGiftCard','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 礼品卡管理列表 - 启用禁用
     * @return void
     */
    public function enableGiftCard(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCard::enableGiftCard($param);

        return $this->success($msg);
    }



    /**
     * 礼品卡后台 - 分类管理列表
     * @param Request $request
     * @return mixed
     */
    public function getGiftCardCateList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardCate::getGiftCardCateList($param);

        return $this->success($data);
    }


    public function getGiftCardCateData(Request $request)
    {
        $param = $request->param();
        $data = GiftCardCate::getGiftCardCateData($param);
        return $this->success($data);
    }


    /**
     * 分类管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addGiftCardCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['cate_tag_name'])) return $this->fail('cate_tag_name不能为空');
        if(empty($param['sort'])) return $this->fail('sort不能为空');
        if(empty($param['icon'])) return $this->fail('icon不能为空');

        $res = GiftCardCate::addGiftCardCate($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }




    /**
     * 分类管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateGiftCardCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['cate_tag_name'])) return $this->fail('cate_tag_name不能为空');

        $res = GiftCardCate::updateGiftCardCate($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：分类名称：{$param['cate_tag_name']}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','分类管理列表','updateGiftCard','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }



    /**
     * 分类管理列表 - 删除
     * @return void
     */
    public function deleteGiftCardCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCardCate::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','分类管理列表','deleteGiftCardCate','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 分类管理列表 - 启用禁用
     * @return void
     */
    public function enableGiftCardCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardCate::enableGiftCardCate($param);

        return $this->success($msg);
    }




    /**
     * 礼品卡后台 - 挂失管理列表
     * @param Request $request
     * @return mixed
     */
    public function getReportGiftList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardReport::getReportGiftList($param);

        return $this->success($data);
    }


    /**
     * 挂失管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addReportGift(Request $request)
    {
        try {
            $param = $request->post();
            if (empty($param['phone'])) return $this->fail('phone不能为空');
            if (empty($param['user_name'])) return $this->fail('user_name不能为空');
            if (empty($param['idcard'])) return $this->fail('idcard不能为空');
            if (empty($param['content'])) return $this->fail('content不能为空');
            if (empty($param['order_id'])) return $this->fail('order_id不能为空');

            $res = GiftCardReport::addReportGift($param);
            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');
        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }




    /**
     * 挂失管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateReportGift(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['content'])) return $this->fail('content不能为空');
        if(empty($param['card_user_id'])) return $this->fail('card_user_id不能为空');

        $res = GiftCardReport::updateReportGift($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：标题：{$param['content']}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','挂失管理列表','updateReportGift','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }



    /**
     * 挂失管理列表 - 删除
     * @return void
     */
    public function deleteReportGift(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCardReport::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','挂失管理列表','deleteReportGift','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 挂失管理列表 - 启用禁用
     * @return void
     */
    public function enableReportGift(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardReport::enableReportGift($param);

        return $this->success($msg);
    }


    /**
     * 礼品卡后台 - 购卡管理列表
     * @param Request $request
     * @return mixed
     */
    public function getGiftUserList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardUser::getGiftUserList($param);

        return $this->success($data);
    }



    /**
     * 购卡管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateGiftUser(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCardUser::updateGiftUser($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为： 祝福语：{$param['bless']}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','购卡管理列表','updateGiftUser','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }


    /**
     * 购卡管理列表 - 查看
     * @param Request $request
     * @return mixed
     */
    public function detailGiftUser(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $detail = GiftCardUser::detailGiftUser($param);
        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 购卡管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteGiftUser(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCardUser::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','购卡管理列表','deleteGiftUser','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 购卡管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableGiftUser(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardUser::enableGiftUser($param);

        return $this->success($msg);
    }




    /**
     * 礼品卡后台 - 属性库管理列表
     * @param Request $request
     * @return mixed
     */
    public function getSysGiftList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardSys::getSysGiftList($param);

        return $this->success($data);
    }


    /**
     * 属性库管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addSysGift(Request $request)
    {
        $param = $request->post();
        if (empty($param['name'])) return $this->fail('name不能为空');

        $param["user_id"] = $this->adminId;
        $res = GiftCardSys::addSysGift($param);
        if ($res > 0) {
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 属性库管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateSysGift(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['name'])) return $this->fail('name不能为空');

        $res = GiftCardSys::updateSysGift($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：属性名称：{$param["name"]}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','属性库管理列表','updateSysGift','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }


    /**
     * 属性库管理列表 - 删除
     * @return void
     */
    public function deleteSysGift(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCardSys::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','属性库管理列表','deleteSysGift','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 属性库管理列表 - 启用禁用
     * @return void
     */
    public function enableSysGift(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardSys::enableSysGift($param);

        return $this->success($msg);
    }



    /**
     * 礼品卡后台 - 特效管理列表
     * @param Request $request
     * @return mixed
     */
    public function getGiftEffectList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardEffect::getGiftEffectList($param);

        return $this->success($data);
    }



    /**
     * 特效管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addGiftEffect(Request $request)
    {
        $param = $request->post();
        if(empty($param['cate_id'])) return $this->fail('cate_id不能为空');
        if(empty($param['file_url'])) return $this->fail('file_url不能为空');

        $res = GiftCardEffect::addGiftEffect($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }




    /**
     * 特效管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateGiftEffect(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['cate_id'])) return $this->fail('cate_id不能为空');
        if(empty($param['file_url'])) return $this->fail('file_url不能为空');

        $res = GiftCardEffect::updateGiftEffect($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：分类id：{$param['cate_id']}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','特效管理列表','updateGiftEffect','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }



    /**
     * 特效管理列表 - 删除
     * @return void
     */
    public function deleteGiftEffect(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCardEffect::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','特效管理列表','deleteGiftEffect','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 特效管理列表 - 启用禁用
     * @return void
     */
    public function enableGiftEffect(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardEffect::enableGiftEffect($param);

        return $this->success($msg);
    }


    /**
     * 礼品卡后台 - 赠送管理列表
     * @param Request $request
     * @return mixed
     */
    public function getGiftCardShareList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardUser::getGiftCardShareList($param);

        return $this->success($data);
    }


    /**
     * 赠送管理列表 - 详情
     * @param Request $request
     * @return mixed
     */
    public function detailGiftCardShare(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $detail = GiftCardUser::detailGiftCardShare($param);

        return $this->success($detail ? $detail->toArray() : []);
    }




    /**
     * 礼品卡后台 - 祝福语管理列表
     * @param Request $request
     * @return mixed
     */
    public function getGiftBlessList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardBless::getGiftBlessList($param);

        return $this->success($data);
    }



    /**
     * 祝福语管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addGiftBless(Request $request)
    {
        $param = $request->post();
        if(empty($param['cate_id'])) return $this->fail('cate_id不能为空');
        if(empty($param['bless'])) return $this->fail('bless不能为空');

        $res = GiftCardBless::addGiftBless($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 祝福语管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateGiftBless(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['cate_id'])) return $this->fail('cate_id不能为空');
        if(empty($param['bless'])) return $this->fail('bless不能为空');

        $res = GiftCardBless::updateGiftBless($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：分类id：{$param['cate_id']}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','祝福语管理列表','updateGiftBless','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }


    /**
     * 祝福语管理列表 - 删除
     * @return void
     */
    public function deleteGiftBless(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = GiftCardBless::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','祝福语管理列表','deleteGiftBless','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 祝福语管理列表 - 启用禁用
     * @return void
     */
    public function enableGiftBless(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardBless::enableGiftBless($param);

        return $this->success($msg);
    }



    /**
     * 礼品卡后台 - 领取管理列表
     * @param Request $request
     * @return mixed
     */
    public function getGiftCardReciveList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardReport::getGiftCardReciveList($param);

        return $this->success($data);
    }


    /**
     * 领取管理列表 - 详情
     * @param Request $request
     * @return mixed
     */
    public function detailGiftCardRecive(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $detail = GiftCardReport::detailGiftCardRecive($param);

        return $this->success($detail ? $detail->toArray() : []);
    }



    /**
     * 礼品卡后台 - 实体卡批次管理列表
     * @param Request $request
     * @return mixed
     */
    public function getCardBatchList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardBatch::getCardBatchList($param);

        return $this->success($data);
    }


    /**
     * 实体卡批次管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addCardBatch(Request $request)
    {
        $param = $request->post();
        if(empty($param['title'])) return $this->fail('title卡批次名称不能为空');
        if(empty($param['total_num'])) return $this->fail('total_num制卡数量不能为空');
        ////if(empty($param['use_day'])) return $this->fail('use_day体验天数不能为空');

        $res = GiftCardBatch::addCardBatch($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 实体卡批次管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateCardBatch(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['title'])) return $this->fail('title卡批次名称不能为空');
        //if(empty($param['total_num'])) return $this->fail('total_num制卡数量不能为空');
       // if(empty($param['use_day'])) return $this->fail('use_day体验天数不能为空');

        $res = GiftCardBatch::updateCardBatch($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：批次名称：{$param['title']}.";
        SystemOperationLog::addSystemLog($admin_id,'giftcard','实体卡批次管理列表','updateCardBatch','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }



    /**
     * 实体卡批次管理列表 - 启用禁用
     * @return void
     */
    public function enableCardBatch(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardBatch::enableCardBatch($param);

        return $this->success($msg);
    }



    /**
     * 礼品卡后台 - 实体卡管理列表
     * @param Request $request
     * @return mixed
     */
    public function getCardNumberList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardNumber::getCardNumberList($param);

        return $this->success($data);
    }


    /**
     * 实体卡管理列表 - 启用禁用
     * @return void
     */
    public function enableCardNumber(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = GiftCardNumber::enableCardNumber($param);

        return $this->success($msg);
    }


    /**
     * 实体卡管理列表 - 已发货
     * @return void
     */
    public function updateCardNumberState(Request $request)
    {
        $param = $request->post();
        if(empty($param['card_number'])) return $this->fail('card_number不能为空');

        try {
            $msg = GiftCardNumber::updateCardNumberState($param);
            return $this->success($msg);
        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 打包费管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getConfigCostList (Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = ConfigCost::getConfigCostList($param);

        return $this->success($data);
    }


    /**
     * 打包费管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteConfigCost(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = ConfigCost::where("id", $param['id'])->update(['delete_time'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'config','打包费管理列表','deleteConfigCost','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }



    /**
     * 打包费管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateConfigCost(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['pack_cost'])) return $this->fail('pack_cost不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');

        $res = ConfigCost::updateConfigCost($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：标题：{$param["pack_cost"]}.";
        SystemOperationLog::addSystemLog($admin_id,'config','打包费管理列表','updateConfigCost','编辑',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('编辑成功');
        return $this->fail('编辑失败');
    }


    /**
     * 添加打包费
     * @param Request $request
     * @return mixed
     */
    public function addConfigCost(Request $request)
    {
        $param = $request->param();
        if(empty($param['pack_cost'])) return $this->fail('pack_cost不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');

        $param["admin_id"] = $this->adminId;
        $res = ConfigCost::addConfigCost($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 打包费管理列表 - 启用禁用
     * @return void
     */
    public function enableConfigCost(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = ConfigCost::enableConfigCost($param);

        return $this->success($msg);
    }











}
